//
//  BankCardDetailTableViewCell.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/5.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "BankCardDetailTableViewCell.h"

@implementation BankCardDetailTableViewCell
{
    CGFloat moveNum;
    GLGWView *backV;
    GLGWLabel *comLabel;
    GLGWLabel *bankLabel;
    GLGWLabel *cardNumLabel;
    GLGWButton *statusBtn;
    GLGWView *coverView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self hiderLine:YES];
        GLGWView *view = [[GLGWView alloc] initWithInSuperView:self];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(3));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(114)));
        }];
        view.layer.cornerRadius = 6;
        view.clipsToBounds = YES;
        backV = view;
        
        GLGWImageView *imgV = [[GLGWImageView alloc] initInSuperView:view];
        [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(view);
        }];
        imgV.image = [UIImage imageWithStartColor:[UIColor colorWithHexString:@"#FF666B"] endColor:[UIColor colorWithHexString:@"#CC3C40"]];
        imgV.userInteractionEnabled = YES;
        
        GLGWLabel *comLab = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(15) theColor:[UIColor colorWithHexString:@"#FFFFFF"] inSuperView:view];
        [comLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(view.mas_top).offset(kHeightProportion_In_iPhoneTriploid(11));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(30)));
        }];
        comLab.text = @"北京黑金时空电子商务公司";
        comLabel = comLab;
        
        GLGWLabel *bankLab = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#FFFFFF"] inSuperView:view];
        [bankLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(comLab.mas_left);
            make.top.equalTo(comLab.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(1));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(30)));
        }];
        bankLab.text = @"招商银行";
        bankLabel = bankLab;
        
        GLGWLabel *cardNumLab = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(18) theColor:[UIColor colorWithHexString:@"#FFFFFF"] inSuperView:view];
        [cardNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(comLab.mas_left);
            make.bottom.equalTo(view.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(18));
        }];
        cardNumLab.text = @"1109 0759 7010 206";
        cardNumLabel = cardNumLab;
        
        GLGWButton *btn = [[GLGWButton alloc] initWithTitle:@"可用" titleLableFont:SYSTEMFONT(12) titleLableColor:[UIColor colorWithHexString:@"#FFFFFF"] inSuperView:view];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view.mas_top).offset(kHeightProportion_In_iPhoneTriploid(17));
            make.right.equalTo(view.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(44)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(18)));
        }];
        [btn setBackgroundColor:[UIColor colorWithHexString:@"#FFFFFF" alpha:0.14]];
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = kHeightProportion_In_iPhoneTriploid(9);
        statusBtn = btn;
        
        GLGWView *coverV = [[GLGWView alloc] initWithInSuperView:view];
        coverV.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.24];
        [coverV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.bottom.equalTo(view);
        }];
        coverView = coverV;
        coverV.hidden = YES;

        self.selectionStyle = UITableViewCellSelectionStyleBlue;
        UIView *seleView = [[UIView alloc] init];
        seleView.backgroundColor = [UIColor clearColor];
        self.selectedBackgroundView = seleView;
        self.multipleSelectionBackgroundView = seleView;
    }
    return self;
}

- (void)setSelectedBackgroundView:(UIView *)selectedBackgroundView
{
    selectedBackgroundView.backgroundColor = [UIColor clearColor];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if (!self.editing) {
        return;
    }
    [super setSelected:selected animated:animated];
    
    if (self.editing) {
        [statusBtn setBackgroundColor:[UIColor colorWithHexString:@"#FFFFFF" alpha:0.14]];
        if (_model.status == 1) {
            coverView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.24];
        }
    }
    self.tintColor = [UIColor colorWithHexString:@"#A89A60"];
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    if (editing) {
        [self customMultipleChioce];
    }else{
        [self customMultiple];
    }
}

- (void)customMultipleChioce
{
    moveNum = kWidthProportion_In_iPhoneTriploid(30);
    [self updateMasonry];
    [UIView animateWithDuration:0.5 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)customMultiple
{
    moveNum = 0;
    [self updateMasonry];
    [UIView animateWithDuration:0.5 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)updateMasonry
{
    [backV mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15) + self->moveNum);
        make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15) + self->moveNum);
        make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(3));
        make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(114)));
    }];
}

- (void)setModel:(BankCardDetailModel *)model
{
    _model = model;
    comLabel.text = model.realName;
    bankLabel.text = model.bankName;
    cardNumLabel.text = [NSString getNewBankNumWitOldBankNum:model.cardNum];
    if (model.status == 1) {
        [statusBtn setTitle:@"停用" forState:UIControlStateNormal];
        coverView.hidden = NO;
    } else {
        [statusBtn setTitle:@"启用" forState:UIControlStateNormal];
        coverView.hidden = YES;
    }
}

@end
